 
// prepare the form when the DOM is ready 
$(document).ready(function() { 
     var options = { 
        target:        '#upload_btn',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:        showResponse,  // post-submit callback 
        dataType:	   'xml',
        clearForm:     true,
        timeout:       3000 
     }; 
    // bind to the form's submit event 
    $('#upload-form').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
         return false; 
    }); 
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
     $('#upload_btn').attr('value', '正在上传...');
     $('#upload_btn').attr('disabled', 'disabled');
     return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  { 
 	var avatarLink = $(responseText).find('message').text();
 	$('#preview-avatar').attr('src',avatarLink);
    $('#upload_btn').attr('value', '上传成功！');
    $('#upload_btn').removeAttr("disabled");
} 